<template>
  <div class="wrapper">
    <div class="login-box">
      <div class="logo">
        <img src="@/assets/images/logo.png" height="120px" alt="">
      </div>
      <!-- <h3 class="title">登录界面</h3> -->
      <div>{{ info }}</div>
      <el-form :model="loginForm" status-icon :rules="rules" ref="ruleForm" label-width="60px" class="demo-ruleForm">
        <el-form-item label="账号" prop="username">
          <el-input type="text" v-model="loginForm.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item class="btn">
          <el-button type="primary" @click="submitForm">登录</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
  
<script>
import { mapMutations, mapState } from 'vuex';

export default {
  computed: {
    ...mapState("loginModule", ["userinfo"]),
  },
  data() {
    var validateUser = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入账号'));
      } else {
        callback();
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        callback();
      }
    };
    return {
      info: '',
      loginForm: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          { validator: validateUser, trigger: 'blur' }
        ],
        password: [
          { validator: validatePass, trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    ...mapMutations('loginModule', ['setUser']),
    submitForm() {

      this.$api.login.login().then(res => {
        console.log(res);
      }).catch(err => {
        console.log(err);
      })

      this.$api.login2.login2().then(res => {
        console.log(res);
      }).catch(err => {
        console.log(err);
      })

      //   if (this.loginForm.username == '') {
      //     this.$message({
      //       message: '请输入用户名',
      //       type: 'warning'
      //     });
      //     return;
      //   }
      //   if (this.loginForm.password == '') {
      //     this.$message({
      //       message: '请输入密码',
      //       type: 'warning'
      //     });
      //     return;
      //   }

      //   if (this.loginForm.username == this.$store.state.loginModule.userinfo.user && this.loginForm.password == this.$store.state.loginModule.userinfo.password) {
      //     //存储本地
      //     localStorage.setItem('user', JSON.stringify(this.loginForm))
      //     //跳转
      //     this.$router.push('/').catch(() => true)
      //   } else {
      //     this.$message({
      //       message: '用户名或密码不正确',
      //       type: 'warning'
      //     });
      //   }
      // },
      // resetForm(formName) {
      //   this.$refs[formName].resetFields();
      // }
    }
  }
}
</script>
  
<style lang='less' scoped>
.wrapper {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  // background: linear-gradient(to bottom right, blue, rgb(251, 40, 75));
  // background: #104468;
}

.login-box {
  width: 400px;
  height: 260px;
  padding: 20px;
  margin: 0 auto;
  margin-top: 180px;
  border-radius: 10px;

  border: 1px solid #eee;
  background: #fff;
  position: relative;
}

.logo {
  position: absolute;
  width: 120px;
  height: 120px;
  background: #f7f7f7;
  border-radius: 50%;
  overflow: hidden;
  top: -80px;
  left: 50%;
  margin-left: -60px;
  padding: 8px;

  img {
    border-radius: 50%;
    background: #fff;
  }
}

.demo-ruleForm {
  margin-top: 60px;
}

.title {
  margin-bottom: 30px;
  text-align: center;
  color: #666;
}

.btn {
  text-align: center;
  margin-left: -30px;
}
</style>